from typing import *
from leetcode.editor.common.node import *


# leetcode submit region begin(Prohibit modification and deletion)
class Solution(object):
    def getModifiedArray(self, length, updates):
        arr = [0] * length
        df = self.deffrient(arr)
        df.getModifiedArray(updates)
        return df.result(length)

    class deffrient():
        # 差分数组类
        def __init__(self, ll):
            n = len(ll)
            self.per_nums = [0] * (n + 1)
            self.per_nums[0] = ll[0]
            for i in range(1, n):
                self.per_nums[i] = ll[i] - ll[n - 1]

        def getModifiedArray(self, updates):
            for i in range(0, len(updates)):
                left, right, inc = updates[i][0], updates[i][1], updates[i][2]
                self.per_nums[left] += inc
                if right + 1 < len(self.per_nums):
                    self.per_nums[right + 1] -= inc

        def result(self, n):
            res = [0] * n
            res[0] = self.per_nums[0]
            for i in range(1, n):
                res[i] = self.per_nums[i] + res[i - 1]
            return res
# leetcode submit region end(Prohibit modification and deletion)


if __name__ == '__main__':
    solution = Solution()
    solution.getModifiedArray(5,[[1,3,2],[2,4,3],[0,2,-2]])
    # your test code here